package cn.zj.admin.modules.issues.attr;

import cn.zj.admin.attr.ModelAttr;
import cn.zj.admin.modules.issues.domain.Role;
import cn.zj.admin.modules.issues.repository.RoleRepository;
import com.zj.utils.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xi.yang
 * @create 2020-10-16 19:03
 **/
@Component
public class RoleModelAttr implements ModelAttr {
    @Autowired
    private RoleRepository roleRepository;

    @Override
    public void setAttr(HttpServletRequest request, ModelMap modelMap) {
        String id = request.getParameter("id");
        Role role = roleRepository.findById(id).orElseThrow(() -> new ServiceException("not found role:" + id));
        modelMap.addAttribute("data", role);
    }
}
